package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.BaseResponse;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.bean.sketch.SysSketchBean;
import com.ruoyi.system.service.ISysSketchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图文内容Controller
 * 
 * @author rakic
 * @date 2024-01-26
 */
@RestController
@RequestMapping("/system/sketch")
public class SysSketchController extends BaseController
{
    @Autowired
    private ISysSketchService sysSketchService;

    /**
     * 查询图文内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSketchBean sysSketchBean)
    {
        startPage();
        List<SysSketchBean> list = sysSketchService.selectSysSketchList(sysSketchBean);
        return getDataTable(list);
    }

    /**
     * 导出图文内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:export')")
    @Log(title = "图文内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSketchBean sysSketchBean)
    {
        List<SysSketchBean> list = sysSketchService.selectSysSketchList(sysSketchBean);
        ExcelUtil<SysSketchBean> util = new ExcelUtil<SysSketchBean>(SysSketchBean.class);
        util.exportExcel(response, list, "图文内容数据");
    }

    /**
     * 获取图文内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:query')")
    @GetMapping(value = "/{sketchId}")
    public BaseResponse getInfo(@PathVariable("sketchId") Long sketchId)
    {
        return success(sysSketchService.selectSysSketchBySketchId(sketchId));
    }

    /**
     * 新增图文内容
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:add')")
    @Log(title = "图文内容", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResponse add(@RequestBody SysSketchBean sysSketchBean)
    {
        sysSketchBean.setAuthor(getUsername());
        return toAjax(sysSketchService.insertSysSketch(sysSketchBean));
    }

    /**
     * 修改图文内容
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:edit')")
    @Log(title = "图文内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResponse edit(@RequestBody SysSketchBean sysSketchBean)
    {
        return toAjax(sysSketchService.updateSysSketch(sysSketchBean));
    }

    /**
     * 删除图文内容
     */
    @PreAuthorize("@ss.hasPermi('system:sketch:remove')")
    @Log(title = "图文内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sketchIds}")
    public BaseResponse remove(@PathVariable List<Long> sketchIds)
    {
        return toAjax(sysSketchService.deleteSysSketchBySketchIds(sketchIds));
    }


}
